//
//  AppDelegate.swift
//  月升
//
//  Created by qinjiangtao on 2024/1/24.
//

import UIKit
import Bugly

@main
class AppDelegate: UIResponder, UIApplicationDelegate, WXApiDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        window = UIWindow(frame: UIScreen.main.bounds)
        window?.backgroundColor = .white
        window?.switchRootCtrl()
        window?.makeKeyAndVisible()
        
        // 注册微信
        WXApi.registerApp(WXAPPID, universalLink: UNIVERSAL_LINK)
        
        launchExample02(HomeViewController())
        let config = BuglyConfig()
        config.debugMode = true
        Bugly.start(withAppId: "fb52f75dfd", config: config)
        return true
    }

    
    // 微信登录
    func application(_ application: UIApplication, handleOpen url: URL) -> Bool {
        return WXApi.handleOpen(url, delegate: self)
    }
    func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
        return WXApi.handleOpen(url, delegate: self)
    }
    func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
        return WXApi.handleOpenUniversalLink(userActivity, delegate: self)
    }
    func onReq(_ req: BaseReq) {
        print(req)
    }
    func onResp(_ resp: BaseResp) {
        print(resp)
        let result: SendAuthResp = resp as! SendAuthResp
        let code = result.code ?? ""
        NotificationCenter.default.post(name: NSNotification.Name(rawValue: "WXLogin") , object: code, userInfo: nil)
    }

    
    func launchExample02(_ homeVC: UIViewController) {
        let imgURL = "\(UserDefaults.standard.object(forKey: "StartDiagram") ?? "")"
        
        let adView = ZLaunchAd.create(waitTime: 5)
        let buttonConfig = ZLaunchSkipButtonConfig()
        buttonConfig.skipBtnType = .none
        let imageResource = ZLaunchAdImageResourceConfigure()
        imageResource.imageNameOrImageURL = imgURL
        imageResource.animationType = .crossDissolve
        imageResource.imageDuration = 3
        imageResource.imageFrame = CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT)
        /// 设置图片、跳过按钮
        adView.setImageResource(imageResource, buttonConfig: buttonConfig, action: {
            let vc = UIViewController()
            vc.view.backgroundColor = UIColor.yellow
            homeVC.navigationController?.pushViewController(vc, animated: true)
        })
    }
}


/**
 java -jar buglyqq-upload-symbol.jar -appid fb52f75dfd -appkey 4d52bcfe-2c11-4075-8a5c-8957532e7817 -bundleid com.moonrise.weauth12 -version 1.0 -buildNo 4 -platform IOS -inputSymbol /Users/lalifa/Desktop/dSYMs
 */


